#include<stdio.h>
#include<stdlib.h>
struct Student
{
        char cName[20];
                int iNumber;
                struct Student* pNext;
};
int iCount;

struct Student* Create()
{
        struct Student* pHead=NULL;
        struct Student* pEnd,*pNew;
        iCount=0;
        pEnd=pNew=(struct Student*)malloc(sizeof(struct Student)); //分配内存
        printf("please first enter Name,then Number\n");
        scanf("%s",&pNew->cName);
        scanf("%d",&pNew->iNumber);
        while(pNew->iNumber!=0)
        {
                iCount++;
                if(iCount==1){
					//第一个的时候
                        pNew->pNext=pHead;//指向空
                        pEnd=pNew;//就是第一个节点
                        pHead=pNew;//就是第一个节点
                }
                else{
					//第二个以及更多
                        pNew->pNext=NULL;//让新节点指向空
                        pEnd->pNext=pNew;//让上一个节点的指针指向新节点
                        pEnd=pNew;//让上一个节点指向新节点
                }
                pNew=(struct Student*)malloc(sizeof(struct Student*));//新节点开辟内存
                scanf("%s",&pNew->cName);
                scanf("%d",&pNew->iNumber);
        }
        free(pNew);//释放pNew指向的内存区
        return pHead;
}

void Print(struct Student* pHead)
{
        struct Student *pTemp;
        int iIndex=1;

        printf("---the List has %d members:----\n",iCount);
        printf("\n");
        pTemp=pHead;

        while(pTemp!=NULL)
        {
                printf("the NO%d member is:\n",iIndex);
                printf("the name is:%s\n",pTemp->cName);
                printf("the number is:%d\n",pTemp->iNumber);
                printf("\n");
                pTemp=pTemp->pNext;
                iIndex++;
        }
}

struct Student* Insert(struct Student* pHead)
{
	struct Student* pNew;
	printf("---Insert member at first---\n");
	pNew=(struct Student*)malloc(sizeof(struct Student));
	scanf("%s",&pNew->cName);
	scanf("%d",&pNew->iNumber);
	
	pNew->pNext=pHead;
	pHead=pNew;
	iCount++;
	return pHead;
}

void Delete(struct Student* pHead,int iIndex)
{
	int i;
	struct Student* pTemp;
	struct Student* pPre;
	pTemp=pHead;
	pPre=pTemp;
	
	printf("-----delete NO%d member------\n",iIndex);
	for(i=1;i<iIndex;i++){
		pPre=pTemp;
		pTemp=pTemp->pNext;
	}
	pPre->pNext=pTemp->pNext;
	free(pTemp);
	iCount--;
}


int main()
{
                struct Student* pHead;
                pHead=Create();				
				pHead=Insert(pHead);
				Delete(pHead,2);
                Print(pHead);


        return 0;
}
